import {
  Button,
  Cell,
  CellGroup,
  Icon,
  Image,
  Col,
  Row,
  Popup,
  Toast,
  Calendar,
  Cascader,
  Checkbox,
  CheckboxGroup,
  DatetimePicker,
  Field,
  Form,
  NumberKeyboard,
  PasswordInput,
  Picker,
  Radio,
    RadioGroup,
  Rate,
  Search,
  Slider,
  Stepper,
  Switch,
  Uploader,
  ActionSheet,
  Dialog,
  DropdownMenu,
  DropdownItem,
  Loading,
  Notify,
  Overlay,
  PullRefresh,
  ShareSheet,
  SwipeCell,
  Badge,
  Circle,
  Collapse,
  CollapseItem,
  CountDown,
  Divider,
  Empty,
  ImagePreview,
  Lazyload,
  List,
  NoticeBar,
  Popover,
  Progress,
  Skeleton,
  Steps,
  Step,
  Sticky,
  Swipe,
  SwipeItem,
  Tag,
  Grid,
  GridItem,
  IndexBar,
  IndexAnchor,
  NavBar,
  Pagination,
  Sidebar,
  SidebarItem,
  Tab,
  Tabs,
  Tabbar,
  TabbarItem,
  TreeSelect,
  AddressEdit,
  AddressList,
  Area,
  Card,
  ContactCard,
  ContactEdit,
  ContactList,
  CouponCell,
  CouponList,
  GoodsAction,
  GoodsActionIcon,
  GoodsActionButton,
  SubmitBar,
  Sku,
} from "vant"

export const Vant = {}

export default {
  install(Vue) {
    [
      Button,
      Cell,
      CellGroup,
      Icon,
      Image,
      Col,
      Row,
      Popup,
      Toast,
      Calendar,
      Cascader,
      Checkbox,
      CheckboxGroup,
      DatetimePicker,
      Field,
      Form,
      NumberKeyboard,
      PasswordInput,
      Picker,
      Radio,
            RadioGroup,
      Rate,
      Search,
      Slider,
      Stepper,
      Switch,
      Uploader,
      ActionSheet,
      Dialog,
      DropdownMenu,
      DropdownItem,
      Loading,
      Notify,
      Overlay,
      PullRefresh,
      ShareSheet,
      SwipeCell,
      Badge,
      Circle,
      Collapse,
      CollapseItem,
      CountDown,
      Divider,
      Empty,
      ImagePreview,
      Lazyload,
      List,
      NoticeBar,
      Popover,
      Progress,
      Skeleton,
      Steps,
      Step,
      Sticky,
      Swipe,
      SwipeItem,
      Tag,
      Grid,
      GridItem,
      IndexBar,
      IndexAnchor,
      NavBar,
      Pagination,
      Sidebar,
      SidebarItem,
      Tab,
      Tabs,
      Tabbar,
      TabbarItem,
      TreeSelect,
      AddressEdit,
      AddressList,
      Area,
      Card,
      ContactCard,
      ContactEdit,
      ContactList,
      CouponCell,
      CouponList,
      GoodsAction,
      GoodsActionIcon,
      GoodsActionButton,
      SubmitBar,
      Sku,
    ].forEach((VantComp) => {
      installVant(Vue, VantComp) // 注册Vant



      // installApp(Vue,'Icon')// 注册Vant二次封装的组件app+Vant
      installVantComp(Vue, VantComp)
    })

  }
}

const vantCompReg = /^van-/
const newVantCompName = "Vant"
function installVant(Vue, VantComp) {
  Vue.use(VantComp)
}

function installVantComp(Vue, VantComp) {
  const { name='' } = VantComp;
//  console.log(name,VantComp);
  if (!name) {  // 指令 Lazyload 懒加载
    // console.log(1,name,VantComp);
    /* Vue.filter('my-filter', function (value) {
      // 返回处理后的值
    }) */
    return;
  } else if (typeof VantComp === 'function') { // 方法 
    // 全局调用——弹框 Toast\Dialog \Loading \Notify \ImagePreview
    Vant[name]=VantComp
    return;
  }

  // 组件
  
  const dirname = name.replace(vantCompReg, "").replace(/-[a-z]/g, (s) => {
    return s[1].toUpperCase()
  })
  const compName = newVantCompName + dirname.replace(/^[a-z]/, s => s.toUpperCase());
  Vue.component(compName, Vue.extend({...VantComp,name:compName}) /* () => import(VantComp) */)
  
}


